<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
	<title>基础数据-店仓管理</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>libs/bootstrap-3.3.7-dist/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/reset.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/iframe.css">
</head>
<body>
	<div id="mainContent">
		<div id="mainContent_content">
			<div class="page_header"><a>店仓管理</a></div>
			<div class="search">
			<form action="<%=basePath %>shop/listShop.do" method="post" class="form">
				<input type="hidden" name="currentPage" value="1">
				<p>
						<label>店仓代码</label>
						<input type="text" name="storecode" value="${shopPage.storecode }" class="form-control"></input>
						<label>店仓名称</label>
						<input type="text" name="annexname" value="${shopPage.annexname }" class="form-control"></input>
						<label>状态</label>
						<select name="annexpath" class="form-control select">
							<option value="">全部</option>
							<option value="可用" ${shopPage.annexpath=="可用"?"selected":"" }>可用</option>
							<option value="不可用" ${shopPage.annexpath=="不可用"?"selected":"" }>不可用</option>
						</select>
					<span class="btn">
						<input type="submit" value="查询"  class="btn btn1"></input>		
							<c:if test="${isAdd }">
								<input type="button" value="新增" onclick="addShop();"  class="btn btn1"></input>
							</c:if>
								<input type="button" value="编辑" onclick="toEditShop();" class="btn btn2"></input>
							<c:if test="${isDelete }">
								<input type="button" value="删除" onclick="toDeleteShop();" class="btn btn_danger"></input>
							</c:if>
					</span>
				</p>
			</form>
			</div>
			<div class="tableBox box" >
				<table class="table table-bordered table_text_center">
					<thead>
						<tr>
							<th></th>
							<th style="width:140px;">操作</th>
							<th>店仓代码</th>
							<th>店仓名称</th>
							<th>状态</th>
							<th>创建时间</th>
							<th>创建人</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${shopList}" var="shop" varStatus="i">
							<tr onclick="selectRow(this);">
								<td><label class="radio"><input type="radio" name="operateShop" value="${shop.shopid }"><span class="radio_icon"></span></label></td>
								<td>
									<a class="btn btn-xs btn1" onclick="editShop(${shop.shopid });">编辑</a>
									<c:if test="${isDelete }">
										<a class="btn btn-xs btn_danger" onclick="confirmDeleteShop(${shop.shopid });">删除</a>
									</c:if>
								</td>
								<td>${shop.storecode }</td>
								<td>${shop.annexname }</td>
								<td>${shop.annexpath }</td>
								<td><fmt:formatDate value="${shop.createtime }"
										type="date" /></td>
								<td>${shop.createpersonname }</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
			<jsp:include page="/jsp/basic/page.jsp"></jsp:include>
		</div>
		<jsp:include page="/jsp/basicData/shopManage/addShop.jsp"></jsp:include>
		<jsp:include page="/jsp/basic/prompt.jsp"></jsp:include>
	</div>
	<script src="<%=basePath %>js/jquery-3.2.1.min.js"></script>
	<script src="<%=basePath %>libs/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
	<script src="<%=basePath %>My97DatePickers/WdatePicker.js"></script>
	<script src="<%=basePath %>js/public.js"></script>
	<script type="text/javascript">
	function selectRow(obj){
		$(obj).find('input:radio[name="operateShop"]')[0].checked=true;
	}
	
	function toEditShop(){
		var radio=$('input:radio[name="operateShop"]:checked');
		if(!radio.val()){
			Prompt.alert("提示","请先选中需要编辑的店仓！");
			return;
		}
		editShop(radio.val());
	}
	
	function editShop(shopid){
		location.href="<%=basePath %>shop/toUpdate.do?shopid="+shopid;
	}
	
	function toDeleteShop(){
		var radio=$('input:radio[name="operateShop"]:checked');
		if(!radio.val()){
			Prompt.alert("删除提示","请先选中需要删除的店仓！");
			return;
		}
		confirmDeleteShop(radio.val());
	}
		
	function confirmDeleteShop(id){
		var delFunc=function(){
			$.ajax({
				url:"<%=basePath %>shop/delete.do",
				type:"post",
				async : false,
				dataType:"json",
				data : "shopid="+id,
				success:function(data){
					if(data.result=="success"){
						Prompt.alert("删除提示","店仓已删除！",Prompt.refresh);
					}
				},
				error :function(){
					Prompt.alert("删除提示","服务器无响应，请刷新页面后重试！");
				}
			});
		}
		Prompt.confirm("提示","确认要删除该店仓吗?删除后无法恢复",delFunc);
	}
	</script>
</body>
</html>